attribute vec3 inPosition;
attribute vec4 inTex2dCoord;
uniform mat4 inProjMat;
uniform mat4 inViewMat;
uniform sampler2D cm_hightMap;
uniform float cm_BaseHeight;
uniform float cm_HeightScale;
uniform float cm_XLength;
uniform float cm_YLength;
varying vec2 outTexCoord[2];

float terrainHeight(float x, float y)
{
	float fValueHeight = texture2D(cm_hightMap, vec2(x / cm_XLength, y / cm_YLength)).r;
	return cm_HeightScale * (fValueHeight + cm_BaseHeight);
}

void main(void)
{
	vec4 v = vec4(inPosition, 1.0);
	v.z = terrainHeight(v.x, v.y);
	gl_Position=inProjMat*inViewMat*v;
	outTexCoord[0] = vec2(inTex2dCoord.x,inTex2dCoord.y);
	outTexCoord[1] = vec2(inTex2dCoord.z,inTex2dCoord.w);
}